package com.example.selenium.queue.rabbitmq.config;

import com.example.selenium.queue.rabbitmq.config.RabbitMqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfigDirect {

    /**
     * 直连交换机
     */
    @Bean
    public DirectExchange directExchangeWaybill() {
        // 参数意义:
        // name: 名称
        // durable 持久化: true
        // autoDelete: 自动删除
        return new DirectExchange(RabbitMqConstants.DIRECT_EXCHANGE_WAYBILL, true, false);
    }

    /**
     * 运单列表队列
     */
    @Bean
    public Queue queueWaybillList() {
        return new Queue(RabbitMqConstants.QUEUE_WAYBILL_LIST, true);
    }

    /**
     * 运单详情队列
     */
    @Bean
    public Queue queueWaybillDetail() {
        return new Queue(RabbitMqConstants.QUEUE_WAYBILL_DETAIL, true);
    }

    /**
     * 支付详情队列
     */
    @Bean
    public Queue queuePayInfoDetail() {
        return new Queue(RabbitMqConstants.QUEUE_PAYINFO_DETAIL, true);
    }

    /**
     * 绑定
     */
    @Bean
    public Binding bindWaybillList() {
        return BindingBuilder.bind(queueWaybillList())
                             .to(directExchangeWaybill())
                             .with(RabbitMqConstants.DIRECT_ROUTING_KEY_WAYBILL_LIST);
    }

    /**
     * 绑定运单详情
     */
    @Bean
    public Binding bindWaybillDetail() {
        return BindingBuilder.bind(queueWaybillDetail())
                .to(directExchangeWaybill())
                .with(RabbitMqConstants.DIRECT_ROUTING_KEY_WAYBILL_DETAIL);
    }

    /**
     * 绑定支付详情
     */
    @Bean
    public Binding bindPayInfoDetail() {
        return BindingBuilder.bind(queuePayInfoDetail())
                .to(directExchangeWaybill())
                .with(RabbitMqConstants.DIRECT_ROUTING_KEY_PAYINFO_DETAIL);
    }


}
